<!DOCTYPE html>
<html>
{include file="public/header" /}
<body>

<div class="layui-fluid" id="app">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card" >
                <div class="layui-card-body">
                    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                        <ul class="layui-tab-title">
                            <li class="layui-this">所有文章</li>
                            <li onclick="go('add_article')">添加文章</li>
                            <li onclick="go('article_fenlei')">文章分类</li>
                        </ul>
                        <div class="layui-tab-content" style="padding-left: 0px;padding-right: 0px">

                            <div class="layui-tab-item layui-show">

                                <div>
                                    <div class="layui-btn-group">
                                        <button class="layui-btn " onclick="del();">批量删除</button>
                                        <!--<button class="layui-btn" >批量操作1</button>-->
                                    </div>
                                </div>

                                <div class="layadmin-trailer ">

                                    <table class="layui-table" lay-skin="line">

                                        <thead>
                                        <tr>
                                            <th></th>
                                            <th>#ID</th>
                                            <th>标题</th>
                                            <th>分类</th>
                                            <!--<th>创建时间</th>-->
                                            <th>点击量</th>
                                            <th>缩略图</th>
                                            <th>发布时间</th>
                                            <th>是否推荐</th>
                                            <th>是否发布</th>
                                            <th></th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="(item,index) in items" :data_id="item.id">
                                            <td style="width: 20px;text-align: center">
                                                <input type="checkbox" class="vue_index" name="id" :value="item.id"
                                                       style="zoom: 150%">
                                            </td>
                                            <td>{{item.id}}</td>
                                            <td>{{item.title}}</td>
                                            <td>{{item.fenlei}}</td>
                                            <td>{{item.click_rate}}</td>
                                            <td><img :src="item.small_img" class="layui-circle2"></td>
                                            <td>{{item.release_time}}</td>
                                            <!--<td>{{item.tuijian}}</td>-->
                                            <td  v-if="item.tuijian == 0">未推荐</td>
                                            <td  v-if="item.tuijian == 1">推荐</td>
                                            <!--<td>{{item.fabu}}</td>-->
                                            <td  v-if="item.fabu == 0">未发布</td>
                                            <td  v-if="item.fabu == 1">发布</td>
                                            <td>

                                                <div class="layui-btn-group">
                                                    <button class="layui-btn layui-btn-sm layui-btn-primary" onclick="edit(this)"
                                                            :data_id="item.id" :data_index="index">编辑
                                                    </button>
                                                    <button id="tuijian" class="layui-btn layui-btn-sm layui-btn-primary" onclick="set_tuijian(this)"
                                                            :data_id="item.id" :data_index="index">推荐
                                                    </button>
                                                </div>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                                <div id="demo7"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    //vue对象
    var app = new Vue({
        el: '#app',
        data: {
            check: [],
            curr: 1,//当前页
            limit: 10,//当前页
            items: [],
            tj_data:0
        }
    });

    //初始数据
    function init() {
        layer.load(2);
        $.get('/admin/article/edit_article_fenlei', {page: app.curr, limit: app.limit,tj_data:app.tj_data,fname:"{$Request.param.fenlei}"},
            function (res) {
                layer.closeAll();
                app.items = res.data;
            }
        );
    }

    //点击编辑弹出弹框
    function edit(that) {

        var data_id = $(that).attr('data_id');
        layer.open({

            type: 2,
            title: '编辑',
            shadeClose: true,
            shade: 0.01,
            area: ['80%', '80%'],
            content: "{:url('edit_article')}?id=" + data_id //iframe的url

        });


    }

    //推荐
    function set_tuijian(obj) {

        var index = layer.confirm('确认继续执行？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            var tj = document.getElementById('tuijian');
            var data_id = $(obj).attr('data_id');
            console.log(data_id+'aaaa');
            $.post('{:url("set_tuijian")}',{tj_data:1,data_id:data_id},function (res) {
                if (res.code == 1) {
                    if (tj.isClick==true){
                        obj.field['tuijian']=1;
                    }
                    layer.msg(res.msg, {icon: 1})
                    init()
                }
                layer.close(index);
            });
        }, function () {
            layer.close(index);
        });


    }

    //获取批量IDS
    function getCheckBox() {
        var check = [];
        $.each($('input[type=checkbox]:checked.vue_index'), function () {
            check.push($(this).val());
        });
        return check;
    }

    //批量删除
    function del() {
        var ids = getCheckBox();
        if (ids.length > 0) {
            var index = layer.confirm('确认继续执行？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.post('{:url("del")}', {ids: ids}, function (res) {
                    if (res.code == 1) {
                        layer.msg(res.msg, {icon: 1})
                        init();
                    }
                    layer.close(index);
                });
            }, function () {
                layer.close(index);
            });
        }


    }

    //按需引入layui模块
    layui.use(['laypage', 'layer','table','element'], function () {
        var laypage = layui.laypage
            , layer = layui.layer;
        var table = layui.table;
        var elemnet = layui.element;
        //完整功能
        laypage.render({
            elem: 'demo7'
            , count: "{$count}"
            , limits: [10, 20]
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
            , jump: function (obj) {
                console.log(obj)
                app.curr = obj.curr;
                app.limit = obj.limit;
                init();
            }
        });

    });


</script>


</body>
</html>




